using System;
using System.Web.UI;

using MettleSystems.dashCommerce.Core;
using OpenNetCommerce.Localization;

namespace MettleSystems.dashCommerce.Web.admin.controls.sitesettings {
  public partial class widgets : SiteSettingsControl {
  
    #region Page Events

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected override void Page_Load(object sender, EventArgs e) {
      try {
        base.Page_Load(sender, e);
        if (view.Equals("w")) {
          SetWidgetsProperties();
          if (!Page.IsPostBack) {
            chkDisplayNarrowByManufacturer.Checked = SiteSettings.DisplayNarrowByManufacturer;
            chkDisplayNarrowByPrice.Checked = SiteSettings.DisplayNarrowByPrice;
            chkDisplaySortBy.Checked = SiteSettings.DisplaySortBy;
            chkDisplayNarrowCategory.Checked = SiteSettings.DisplayNarrowCategory;
          }
        }
      }
      catch (Exception ex) {
        Logger.Error(typeof(widgets).Name + ".Page_Load", ex);
        base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message);
      }
    }

    /// <summary>
    /// Handles the Click event of the btnSave control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void btnSave_Click(object sender, EventArgs e) {
      try {
        SiteSettings.DisplayNarrowByManufacturer = chkDisplayNarrowByManufacturer.Checked;
        SiteSettings.DisplayNarrowByPrice = chkDisplayNarrowByPrice.Checked;
        SiteSettings.DisplaySortBy = chkDisplaySortBy.Checked;
        SiteSettings.DisplayNarrowCategory = chkDisplayNarrowCategory.Checked;
        base.Save(SiteSettings);
      }
      catch (Exception ex) {
        Logger.Error(typeof(widgets).Name + ".btnSave_Click", ex);
        base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message);
      }
    }
    
    #endregion
    
    #region Methods
    
    #region Private

    /// <summary>
    /// Sets the widgets properties.
    /// </summary>
    private void SetWidgetsProperties() {
      this.Page.Title = LocalizationUtility.GetText("titleSiteSettingsWidgets");
    }
    
    #endregion
    
    #endregion
    
  }
}